package com.work.keep.activity;

import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Toast;

import com.work.keep.R;
import com.work.keep.adapter.MyHomePageFragmentAdapter;
import com.work.keep.base.BaseActivity;
import com.work.keep.fragment.DynamicFragment;
import com.work.keep.fragment.UserInforFragment;
import com.work.keep.fragment.UserTrainingFragment;
import com.work.keep.view.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/21.
 */
public class HomePageActivity extends BaseActivity implements View.OnClickListener {
    private FloatingActionButton fab;
    private NoScrollViewPager viewPager;
    private TabLayout tabLayout;
    private List<Fragment> fragments;
    MyHomePageFragmentAdapter homePageFragmentAdapter;

    @Override
    protected View getLayoutView() {
        return null;
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_homepage;
    }

    @Override
    protected void initView() {
        fab = (FloatingActionButton) findViewById(R.id.fab);
        viewPager = (NoScrollViewPager) findViewById(R.id.homePageViewPager);
        tabLayout = (TabLayout) findViewById(R.id.homePageTabLayout);
        fab.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        fragments = new ArrayList<>();
        fragments.add(new UserTrainingFragment());
        fragments.add(new DynamicFragment());
        fragments.add(new UserInforFragment());
//        fragments.add();
        homePageFragmentAdapter = new MyHomePageFragmentAdapter(getSupportFragmentManager(), this, fragments);
        viewPager.setAdapter(homePageFragmentAdapter);
        tabLayout.setupWithViewPager(viewPager);
        for (int i = 0; i < fragments.size(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            tab.setCustomView(homePageFragmentAdapter.getTabView(i));
        }
    }

    @Override
    public void onClick(View v) {
        Toast.makeText(this, "Floating", Toast.LENGTH_SHORT).show();
    }
}
